package String;

/**
 * @author wuhan
 * @date 2019/9/23 15:51
 */
public class Practice {
    /*
        s1=hoooh
        s2=ooo
     */
    public static String getMaxSubString(String father,String son){
        String max="",min="";
        max=(father.length()>son.length())?father:son;
        min = (max==father)?son:father;
        for (int x=0;x<min.length();x++){
            //第一个循环就是将每次字串长度减一
            for (int y=0,z=min.length()-x;z!=min.length()+1;y++,z++){
                String temp =min.substring(y,z);
//                System.out.println(temp);
                if (father.contains(temp))
                    return temp;
            }
        }
        return null;
    }

    public static void main(String[] args) {
       String s="asdanjkhellosnkclsnd";
       String s1="asaskhellod";
       String maxSubString = getMaxSubString(s, s1);
       System.out.println(maxSubString);
    }

    public static int getSubCount(String str,String key){
        int count=0;
        int index=0;
        while ((index=str.indexOf(key,index))!=-1){
            index=index+key.length();
            count++;
        }
        return  count;
    }





    public static String MyReverse(String string){
        char[] chars = string.toCharArray();
        int start=0;
        int end=chars.length-1;
        char temp;
        while (start<=end){
            temp=chars[start];
            chars[start]=chars[end];
            chars[end]=temp;
            start++;
            end--;
        }
        return new String(chars);
    }

    public static String myTrim(String string){
        int start=0;
        int end=string.length()-1;
        while (start<end&&string.charAt(start)==' '){
            start++;
        }
        while (start<end&&string.charAt(end)==' '){
            end--;
        }
        String substring = string.substring(start, end+1);
        return substring;
    }
}
